﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace sistem
{
    public partial class CasKontrola : UserControl
    {
        Profesor profesor;
        MySqlDataAdapter da = new MySqlDataAdapter();
        DataTable dt = new DataTable();

        public CasKontrola()
        {
            InitializeComponent();
        }
        public CasKontrola(Profesor p, int predmet_id, int razred_id)
        {
            InitializeComponent();
            profesor = p;
            string constring = "server=localhost;user=root;pwd=" + "" + ";database=skola";
            MySqlConnection con = new MySqlConnection(constring);
            MySqlCommand cmd = new MySqlCommand("SELECT c.id, c.pocetak, c.opis, c.dodatne_napomene FROM cas c WHERE c.predmet_id=@PREDMET and c.razred_id=@RAZRED;", con);
            cmd.Parameters.AddWithValue("@PREDMET", predmet_id);
            cmd.Parameters.AddWithValue("@RAZRED", razred_id);
            cmd.CommandType = CommandType.Text;
            da = new MySqlDataAdapter(cmd);
            da.Fill(dt);
            dataGridView1.DataSource = dt;
            dataGridView1.Columns[0].Visible = false;
        }

        private void dataGridView1_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
                da.Update(dt);
            }
            catch(Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
    }
}
